<template>
  <div
      v-loading="loading"
      element-loading-text="配准生成中"
      class="HomeView">
    <div class="home-left">
      <HomeLeft
          @actModeChange="handleActModeChange"
          @deleteCP="deleteCP"
          @showPreview="showPreview"
          @sourceFileUpload="sourceFileUpload"
          @uploadTIF="uploadTIF"
          @loadingCalibration="loading = true"
          @loadedCalibration="loading = false"
          @resetTIF="resetTIF"
          @doExport="doExport"
          ref="HomeLeft"
      ></HomeLeft>
    </div>
    <div class="home-right">
      <HomeRight
          @actModeFinish="actModeFinish"
          @sourceFileUpload="sourceFileUpload"
          @uploadTIF="uploadTIFRight"
          @resetTIF="resetTIF"
          ref="HomeRight"
      ></HomeRight>
    </div>
    <home-preview
        ref="HomePreview"
        @doExport="doExport"
    ></home-preview>
    <tif-export
        ref="TIFExport"
    ></tif-export>
  </div>

</template>
<script>
import HomePreview from "@/views/HomeView/components/HomePreview.vue";
import TifExport from "@/views/HomeView/components/TifExport.vue";

export default {
  components: {
    TifExport,
    HomePreview,
    HomeLeft: () => import("./components/HomeLeft"),
    HomeRight: () => import("./components/HomeRight")
  },
  data() {
    return {
      callback: null,
      loading: false,
    }
  },
  methods: {
    handleActModeChange(actMode, index, callback) {
      this.$refs.HomeRight.actMode = actMode;
      this.$refs.HomeRight.idx = index;
      this.callback = callback;
    },
    actModeFinish(result) {
      this.callback && this.callback(result);
      this.callback = null;
    },
    deleteCP(index) {
      this.$refs.HomeRight.deleteCP(index);
    },
    showPreview(params) {
      this.$refs.HomePreview.show(params);
    },
    sourceFileUpload(result) {
      this.$refs.HomeRight.sourceFileUpload(result);
    },
    resetTIF() {
      this.$refs.HomeRight.resetTIF();
      this.$refs.HomeLeft.resetTIF();
      this.$refs.HomePreview.resetTIF();
      this.$refs.TIFExport.resetTIF();
    },
    uploadTIF(params) {
      this.$refs.HomeRight.uploadTIFStatus(params);
    },
    uploadTIFRight(result) {
      this.$refs.HomeLeft.updateSource(result);
    },
    doExport(targetId,espgCode) {
      this.$refs.TIFExport.show(targetId,espgCode);
    }
  }
};
</script>
<style lang="scss" scoped>
.HomeView {
  width: 100vw;
  height: 100vh;
  background: url(@/assets/images/back.png) no-repeat center center / 100% 100%;
  display: flex;
  flex-wrap: wrap;

  .home-left {
    width: 100%;
    height: 320px;
    padding: 3px 5px;
    box-sizing: border-box;
  }

  .home-right {
    width: 100%;
    height: calc(100vh - 320px);
    padding: 3px 5px;
    box-sizing: border-box;
  }
}
</style>
